package csu.edu.flatprogram.controller.front;

import com.baomidou.mybatisplus.extension.api.R;
import com.sun.org.apache.xerces.internal.impl.xpath.XPath;
import csu.edu.flatprogram.common.CommonResponse;
import csu.edu.flatprogram.entity.Account;
import csu.edu.flatprogram.entity.DonateGoods;
import csu.edu.flatprogram.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flat/accounts")
public class AccountController {

    @Autowired
    private AccountService accountService;

    //查询所有用户信息
    @GetMapping("/select")
    public CommonResponse<List<Account>> getAllAccounts(){
        return accountService.getAllAccounts();
    }

    //根据用户ID查询用户信息
    @GetMapping("/select/{userid}")
    public CommonResponse<Account> getAccountById(@PathVariable("userid") String userid){
        return accountService.getAccountByUserid(userid);
    }

    //根据用户ID查询用户全部募捐物品
    @GetMapping("/donategoods/select/{userid}")
    public CommonResponse<List<DonateGoods>> getDonateGoodsByAccountId(@PathVariable("userid") String userid) {
        return accountService.getDonateGoodsByAccountId(userid);
    }

//    //新增一条用户信息
//    @GetMapping("/{userid}/{password}/{username}/{sex}/{phone}/{address}/add")
//    public CommonResponse<Account> addAccount(@PathVariable("userid") String userid,
//                                              @PathVariable("password") String password,
//                                              @PathVariable("username") String username,
//                                              @PathVariable("sex") String sex,
//                                              @PathVariable("phone") String phone,
//                                              @PathVariable("address") String address){
//        return accountService.addAccount(userid,password,username,sex,phone,address);
//    }
//
//    //根据Id修改一条用户信息
//    @GetMapping("/{userid}/{password}/{username}/{sex}/{phone}/{address}/update")
//    public CommonResponse<Account> updateAccountById(@PathVariable("userid") String userid,
//                                              @PathVariable("password") String password,
//                                              @PathVariable("username") String username,
//                                              @PathVariable("sex") String sex,
//                                              @PathVariable("phone") String phone,
//                                              @PathVariable("address") String address){
//        return accountService.updateAccountById(userid,password,username,sex,phone,address);
//    }


    //根据ID删除一条用户信息
    @DeleteMapping("/delete/{userid}")
    public CommonResponse<Account> deleteAccountById(@PathVariable("userid") String userid){
        return accountService.deleteAccountById(userid);
    }

    //新增一条用户信息
    @PostMapping("/add")
    public CommonResponse<Account> insertAccount(@RequestBody Account account){
        return accountService.insertAccount(account);
    }

    //更新一条用户信息
    @PostMapping("/update")
    public CommonResponse<Account> updateAccount(@RequestBody Account account){
        return accountService.updateAccount(account);
    }

    //根据ID查询单个捐赠物品信息
    @GetMapping("/donategoods/{goodsid}/select")
    public CommonResponse<DonateGoods> getDonateGoodById(@PathVariable("goodsid") int goodsid){
        return accountService.getDonateGoodById(goodsid);
    }







}

